package com.flower.core_service.controller;


import com.flower.core_service.object.entity.AuthUser;
import com.flower.core_service.service.AuthUserRoleService;
import com.flower.core_service.service.AuthUserService;
import com.common.baseModel.JsonResult;
import com.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author flower
 * @since 2022-04-15
 */
@RestController
@RequestMapping("/coreService/system/user")
public class AuthUserController {

    @Autowired
    AuthUserService authUserService;

    @Autowired
    AuthUserRoleService authUserRoleService;

    @PostMapping("/addUser")
    public JsonResult<Object> addAuthUser(AuthUser authUser){
        authUser.setPassword(SecurityUtils.soencryptPassword(authUser.getPassword()));
        authUserService.save(authUser);
      return   JsonResult.isOk();
    }

    @GetMapping("/getAllUser")
    public JsonResult<List<AuthUser>> getAllUser(){
        List<AuthUser> list=authUserService.getAllUser();
        return JsonResult.create(list);
    }

    @GetMapping("/deleteUser/{id}")
    public JsonResult<Object> deleteUser(@PathVariable("id") String id){
        authUserService.deleteUser(id);
        return JsonResult.isOk();
    }
}

